﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using EzDesk.Utility.Extensions;

namespace EzDesk.Deploy
{
    public partial class Mainform : Form
    {
        public Mainform()
        {
            InitializeComponent();
            _presenter = new DeployPresenter(this);

            if (!_presenter.TestDbConnection())
            {
                Environment.Exit(0);
            }

        }

        private DeployPresenter _presenter;

        private void label14_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            _presenter.DoInitData();
        }

        public void displayInitInfo(dynamic initInfo)
        {
            lblConpanyName.Text = initInfo.CompanyName;
            lblCompanyShortname.Text = initInfo.ConpanyShortName;
            lblExpir.Text = ((DateTime)(initInfo.ExpirDate)).ToFullDate();
            lblAdminName.Text = initInfo.AdminName;
            lblDeptCount.Text = initInfo.DeptCount.ToString();
            lblPosCount.Text = initInfo.PositionCount.ToString();
            btnInitData.Enabled = initInfo.CanInitData;

            this.Text = "EzDesk维护程序 - " + initInfo.CompanyName;
        }


        public void displayExpirData(dynamic expirData)
        {
            var date = (DateTime) (expirData.ExpirDate);
            lblExpDate.Text = date.ToFullDate();
            lblExpirStr.Text = (date <= DateTime.Now) ? "已经过期了" : "状态正常";
        }

        private void Mainform_Load(object sender, EventArgs e)
        {
            _presenter.refreshInitInfo();
            _presenter.refreshExpirData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _presenter.refreshInitInfo();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var selectDate = monthCalendar1.SelectionStart;
            _presenter.SetExpirDate(selectDate);
            MessageBox.Show("设置有效期完成");
            _presenter.refreshExpirData();
        }
    }
}
